﻿Imports System.Collections.Generic
Imports NUnit.Framework
Imports PhDir.Model
Imports PhDir.Repository

Namespace UnitTesting.Repository
    <TestFixture()>
    Public Class TestUserRepository

        <Test()>
        Public Sub InsertDummyUserWithEmptyPhoneShouldFail()
            Dim userRepository = New UserRepository()
            Dim department = New Department With {.DepartmentName = "Earth"}
            Dim dummyUser = New User With {.UserName = "Doraemon", .Department = department}
            Dim fakePhone = New Phone With {.User = dummyUser, .PhoneNumber = ""}
            Dim isSuccess = userRepository.Insert(fakePhone)

            Assert.IsFalse(isSuccess)
        End Sub

        <Test()>
        Public Sub InsertDummyUserWithFakePhoneShouldFail()
            Dim userRepository = New UserRepository()
            Dim department = New Department With {.DepartmentName = "Earth"}
            Dim dummyUser = New User With {.UserName = "Doraemon", .Department = department}
            Dim fakePhone = New Phone With {.User = dummyUser, .PhoneNumber = "111"}
            Dim isSuccess = userRepository.Insert(fakePhone)

            Assert.IsFalse(isSuccess)
        End Sub

        <Test()>
        Public Sub InsertDummyUserShouldSuccess()
            Dim userRepository = New UserRepository()
            Dim department = New Department With {.DepartmentName = "Earth"}
            Dim dummyUser = New User With {.UserName = "Doraemon", .Department = department}
            Dim fakePhone = New Phone With {.User = dummyUser, .PhoneNumber = "03 8999 9298"}
            Dim isSuccess = userRepository.Insert(fakePhone)

            Assert.IsTrue(isSuccess)
        End Sub

        <Test()>
        Public Sub UpdateNonExistingUserShouldFail()
            Dim userRepository = New UserRepository()
            Dim nonExistingUser = New User With {.UserId = 0, .UserName = "Nobita"}
            Dim isSuccess = userRepository.Update(nonExistingUser, nonExistingUser)

            Assert.IsFalse(isSuccess)
        End Sub

        <Test()>
        Public Sub UpdateExistingUserShouldSuccess()
            Dim userRepository = New UserRepository()
            Dim nonExistingUser = New User With {.UserId = 16, .UserName = "Nobita"}
            Dim isSuccess = userRepository.Update(nonExistingUser, nonExistingUser)

            Assert.IsTrue(isSuccess)
        End Sub

        <Test()>
        Public Sub DeleteNonExistingUserShouldFail()
            Dim userRepository = New UserRepository()
            Dim nonExistingUser = New User With {.UserId = 0}
            Dim isSuccess = userRepository.Delete(nonExistingUser)

            Assert.IsFalse(isSuccess)
        End Sub

        <Test()>
        Public Sub DeleteExistingUserShouldSuccess()
            Dim userRepository = New UserRepository()
            Dim nonExistingUser = New User With {.UserId = 16}
            Dim isSuccess = userRepository.Delete(nonExistingUser)

            Assert.IsTrue(isSuccess)
        End Sub
    End Class
End Namespace